package com.basin.micro.auth.module.role.controller;

import com.basin.common.core.response.ResponseResult;
import com.basin.common.mp.base.BaseController;
import com.basin.micro.auth.module.role.mapper.RoleMapper;
import com.basin.micro.auth.module.role.pojo.dto.RoleDTO;
import com.basin.micro.auth.module.role.pojo.entity.RoleEntity;
import com.basin.micro.auth.module.role.repository.RoleRepository;
import com.basin.micro.auth.module.role.service.RoleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Sam ZHONG | sammy1997@aliyun.com
 */
@RequestMapping("/role")
@RestController
@Slf4j
@RequiredArgsConstructor
public class RoleController extends BaseController<RoleRepository, RoleEntity, RoleMapper> {

    private final RoleService roleService;

    @PostMapping("/addRole")
    public ResponseResult<Boolean> add(@RequestBody
                                       @Validated(RoleDTO.AddGroup.class)
                                       RoleDTO roleDTO) {
        return this.roleService.add(roleDTO) ? ResponseResult.success() : ResponseResult.fail();
    }

    @PutMapping("/updateRole")
    public ResponseResult<Boolean> update(@RequestBody
                                          @Validated(RoleDTO.UpdateGroup.class)
                                          RoleDTO roleDTO) {
        return this.roleService.update(roleDTO) ? ResponseResult.success() : ResponseResult.fail();
    }
}
